package com.example.jqying.androiddemo.recyclerView.activity;

import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.jqying.androiddemo.R;
import com.example.jqying.androiddemo.recyclerView.adapter.ViewHolerAdapter;

public class ViewHolderActivity extends AppCompatActivity {


    private RecyclerView mRvViewHolder;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_holder);

        mRvViewHolder = (RecyclerView) findViewById(R.id.rv_viewHolder);
        //设置RecycleView布局控制器
        mRvViewHolder.setLayoutManager(new LinearLayoutManager(ViewHolderActivity.this));
        mRvViewHolder.setAdapter(new ViewHolerAdapter(ViewHolderActivity.this, new ViewHolerAdapter.OnitemClickListener() {
            @Override
            public void onClick(int pos) {
                Toast.makeText(ViewHolderActivity.this,"Clicked:"+ pos,Toast.LENGTH_SHORT).show();
            }
        }));

        //添加分割线OK 渐变色
        //这里运用了系统自带的分割线装饰，可以简单的只传入分割线方向
        //或者自定义分割线样式，通过自定义Drawable
        //
        DividerItemDecoration divider = new DividerItemDecoration(this,DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(this,R.drawable.custom_linear_divider));
        mRvViewHolder.addItemDecoration(divider);
    }
}
